﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Survey_SurveyItemAdd : System.Web.UI.Page
{
    protected string action = "";
    protected int SurveyID = 0;
    protected int SurveyItemID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        action = NetRequest.GetQueryString("Action");
        SurveyID = NetRequest.GetQueryInt("SurveyID");
        SurveyItemID = NetRequest.GetQueryInt("SurveyItemID");
        if (!IsPostBack)
        {
            switch (action)
            {
                case "Add": break;
                case "Modify":
                    BindData();
                    btnSumbit.Text = "更新";
                    break;
                case "Delete":
                    BindData();
                    btnSumbit.Text = "删除";
                    btnSumbit.Attributes.Add("onclick", "return confirm('确定要删除吗？');");
                    break;
            }
        }
    }

    private void BindData()
    {
        Whir.BLL.Whir_SurveyItem bll = new Whir.BLL.Whir_SurveyItem();
        Whir.Model.Whir_SurveyItem model = bll.GetModel(SurveyItemID);
        this.TextBox1.Text = model.ItemContent;
        this.TextBox2.Text = model.ItemCount.ToString();
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_SurveyItem bll = new Whir.BLL.Whir_SurveyItem();
        Whir.Model.Whir_SurveyItem model;
        switch (action)
        {
            case "Add":
                model = new Whir.Model.Whir_SurveyItem();
                model.SurveyID = SurveyID;
                model.ItemContent = this.TextBox1.Text;
                model.ItemCount = Convert.ToInt32(this.TextBox2.Text);
                bll.Add(model);
                break;
            case "Modify":
                model = bll.GetModel(SurveyItemID);
                model.ItemContent = this.TextBox1.Text;
                model.ItemCount = Convert.ToInt32(this.TextBox2.Text);
                bll.Update(model);
                break;
            case "Delete":
                model = bll.GetModel(SurveyItemID);
                if (model != null)
                {
                    bll.Delete(SurveyItemID);
                }
                break;
        }
        Response.Redirect("Default.aspx");
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
